﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Othello_Game
{
    public class BoardPositionsValues : IPositionsValues
    {
        private Dictionary<Position, int> PositionValues;

        /// <summary>
        /// Initialize a BoardPositionsValues instance
        /// </summary>
        /// <param name="size"></param>
        public BoardPositionsValues(byte size)
        {
            PositionValues = new Dictionary<Position, int>();

            if (size == GeneralConsts.LEGAL_BOARD_SIZE)
            {
                PositionValues[new Position(0, 0)] = 99;
                PositionValues[new Position(0, 1)] = -8;
                PositionValues[new Position(0, 2)] = 8;
                PositionValues[new Position(0, 3)] = 6;
                PositionValues[new Position(1, 1)] = -24;
                PositionValues[new Position(1, 2)] = -4;
                PositionValues[new Position(1, 3)] = -3;
                PositionValues[new Position(2, 2)] = 7;
                PositionValues[new Position(2, 3)] = 4;
                PositionValues[new Position(3, 3)] = 0;
            }
        }

        #region IPositionsValues Members
        /// <summary>
        /// Return the value for the position index
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public int this[Position index]
        {
            get
            {
                int col = index.Column;
                int row = index.Row;
                Position newPosition;

                if (index.Row >= GeneralConsts.LEGAL_BOARD_SIZE / 2)
                {
                    row = GeneralConsts.LEGAL_BOARD_SIZE - index.Row - 1;
                }

                if (index.Column >= GeneralConsts.LEGAL_BOARD_SIZE / 2)
                {
                    col = GeneralConsts.LEGAL_BOARD_SIZE - index.Column - 1;
                }

                if (row > col)
                {
                    newPosition = new Position(col, row);
                }
                else
                {
                    newPosition = new Position(row, col);
                }

                return PositionValues[newPosition];
            }
        }

        public int this[int row, int col]
        {
            get { return this[new Position(row, col)]; }
        }

        #endregion
    }
}
